//
//  SecondViewController3.m
//  真·豆瓣半完全体
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "SecondViewController3.h"
#import "SecondTableViewCell3_1.h"
#import "UIImageView+WebCache.h"
#import "MyDataBaseHandle.h"
#import "collectModel.h"
@interface SecondViewController3 ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableDictionary *nameDic;

@end

@implementation SecondViewController3
- (void)dealloc{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _title1;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 554) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    UIImage *img = [UIImage imageNamed:@"btn_nav_share@2x.png"];
    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    UIImage *img2 = [UIImage imageNamed:@"btn_nav_back@2x.png"];
    img2 = [img2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:img2 style:UIBarButtonItemStylePlain target:self action:@selector(itemAction2:)];
    self.navigationItem.leftBarButtonItem = item2;
    
    [_tableView registerClass:[SecondTableViewCell3_1 class] forCellReuseIdentifier:@"cell"];
    self.nameDic = [NSMutableDictionary dictionary];
    
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 554;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SecondTableViewCell3_1 *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    
    cell.ratingLabel.text = _rating;
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:_img]];

    
    
    
    return cell;
}


- (void) itemAction:(UIBarButtonItem *) item {
    collectModel *model = [collectModel collectModel];
    model.title = _title1;
    if ([[MyDataBaseHandle sharedMyDataBaseHandle] selectModle:model] == YES) {
                    UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已收藏" preferredStyle:UIAlertControllerStyleAlert];
                    UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
                    [alert2 addAction:alertAction2];
                    [self presentViewController:alert2 animated:YES completion:^{
        
                    }];
    }
    else{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:alertAction];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        [_nameDic setObject:@"已收藏" forKey:_title1];
        self.block(_title1);
        collectModel *model = [collectModel collectModel];
        model.title = _title1;
        [[MyDataBaseHandle sharedMyDataBaseHandle] insertModel:model];
    }
    
}


//- (void) itemAction:(UIBarButtonItem *) item{
//    if (![[_nameDic objectForKey:_title1 ] isEqualToString:@"已收藏"]) {
//        if (![[_nameDic3 objectForKey:_title1 ] isEqualToString:@"已收藏"]) {
//            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
//            UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
//            [alert addAction:alertAction];
//            [self presentViewController:alert animated:YES completion:^{
//                
//            }];
//            [_nameDic setObject:@"已收藏" forKey:_title1];
//            self.block(_title1);
//            collectModel *model = [collectModel collectModel];
//            model.title = _title1;
//            [[MyDataBaseHandle sharedMyDataBaseHandle] insertModel:model];
//        }
//        else{
//            UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已收藏" preferredStyle:UIAlertControllerStyleAlert];
//            UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
//            [alert2 addAction:alertAction2];
//            [self presentViewController:alert2 animated:YES completion:^{
//                
//            }];
//        }
//    }
//    else{
//        UIAlertController *alert2 = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已收藏" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
//        [alert2 addAction:alertAction2];
//        [self presentViewController:alert2 animated:YES completion:^{
//            
//        }];
//    }
//
//}
- (void) itemAction2:(UIBarButtonItem *) item {
    [self.navigationController popToRootViewControllerAnimated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
